package api;

import java.io.Serializable;

/**
 * @author Ann Raboschuk
 */
public class Person implements Serializable, Comparable<Person>
{
   private static final long serialVersionUID = 1L;
   private Long id;
   private String surname, name;
   private Integer age;
   private Character sex;
   private String email;
   private String phone;
   private String address;
   
   public Person()
   {
   }
   
   public Person(String surname, String name, Integer age, Character sex, String email,
         String telephone, String address)
   {
      this.surname = surname;
      this.name = name;
      this.age = age;
      this.sex = sex;
      this.email = email;
      this.phone = telephone;
      this.address = address;
   }
   
   public String toString()
   {
      return "" + id.toString() + "; " + surname + "; " + name + "; " + age + "; " + sex
            + "; " + email + "; " + phone + "; " + address;
   }
   
   public static Person fromString(String object)
   {
      String[] fields = object.split("; ");
      Person person = new Person(fields[1], fields[2],
            Integer.parseInt(fields[3]), fields[4].charAt(0), fields[5],
            fields[6], fields[7]);
      person.setId(Long.parseLong(fields[0]));
      return person;
   }

   @Override
   public int compareTo(Person object)
   {
      Long id2 = new Long(object.getId());
      return new Long(id).compareTo(id2);
   }
   
   public boolean equals(Object object)
   {
      boolean equal = false;
      if (object != null && object instanceof Person)
      {
         Person person = (Person) object;
         equal = (id.equals(person.getId())) && surname.equals(person.getSurname())
               && name.equals(person.getName()) && (age.equals(person.getAge()))
               && (sex.equals(person.getSex())) && email.equals(person.getEmail())
               && phone.equals(person.getPhone())
               && address.equals(person.getAddress());
      }
      return equal;
   }
   
   public Long getId()
   {
      return id;
   }
   
   public String getSurname()
   {
      return surname;
   }
   
   public String getName()
   {
      return name;
   }
   
   public Integer getAge()
   {
      return age;
   }
   
   public Character getSex()
   {
      return sex;
   }
   
   public String getEmail()
   {
      return email;
   }
   
   public String getPhone()
   {
      return phone;
   }
   
   public String getAddress()
   {
      return address;
   }
   
   public void setId(Long id)
   {
      this.id = id;
   }
   
   public void setSurname(String surname)
   {
      this.surname = surname;
   }
   
   public void setName(String name)
   {
      this.name = name;
   }
   
   public void setAge(Integer age)
   {
      this.age = age;
   }
   
   public void setSex(Character sex)
   {
      this.sex = sex;
   }
   
   public void setEmail(String email)
   {
      this.email = email;
   }
   
   public void setPhone(String phone)
   {
      this.phone = phone;
   }
   
   public void setAddress(String address)
   {
      this.address = address;
   }
}
